home *** CD-ROM | disk | FTP | other *** search
/ Power CD-ROM!! 8 / Power CD-ROM 8.iso / os2 / fb_189a / source / dll / filebar.cpp next >
Encoding:
C/C++ Source or Header  |  1994-07-05  |  8.6 KB  |  208 lines

  1. ////////////////////////////////////////////////////////////////////////////////
  2. //
  3. //                    FileBar - Maximize/Movement Hook DLL
  4. //
  5. //         OS/2 Application Launch Facility and WPS Shell Replacement
  6. //
  7. //                         Written By Eric A. Wolf
  8. //                 Copyright (C) 1994 - All Rights Reserved
  9. //
  10. // This source code may be used for reference ONLY!  It is provided AS-IS and no
  11. // guarantees are made as to its utility, functionality or correctness.  It is
  12. // provided solely as a guide to aid aspiring OS/2 2.x Presentation Manager
  13. // programmers in developing their own PM applications.  No modifications are
  14. // to be made to this code for re-release as a same or different product.  This
  15. // code must be distributed (in its original entirety) with the executable
  16. // portion of this product.
  17. //
  18. //          -- Please register this shareware product for $10 today --
  19. //                          See documentation for details
  20. //
  21. // DLL Project Start Date:      March  5, 1994
  22. // DLL Project Completion Date: March  6, 1994
  23. //
  24. // Written using Borland C++ for OS/2, version 1.0
  25. //
  26. // File Last Modified:          July   5, 1994
  27. //
  28. ////////////////////////////////////////////////////////////////////////////////
  29. #define INCL_PMWIN
  30. #define INCL_WINSYS
  31. #define INCL_WIN
  32. #define INCL_PM
  33. #define INCL_WINFRAMEMGR
  34. #define DLL_NAME                 "FILEBAR"        // define the name for our DLL
  35. #define POPUPMENU                9999             // msg to send to signal popup
  36.  
  37. #include <string.h>
  38. #include <stdio.h>
  39. #include "filebar.h"
  40.  
  41.  
  42. //------------------------------------------------------------------------------
  43. // define data we need for our DLL
  44. //------------------------------------------------------------------------------
  45. LONG    messageID;                                // message to popup our menu
  46. SHORT   ScreenY;                                  // height of menubar
  47. SHORT   ScreenHeight;                             // useful screen remaining
  48. HWND    hwndApp;                                  // store handle of app window
  49. HMODULE hmModule;                                 // store module data for app
  50. BOOL    BarAtTop;                                 // is the menubar at the top
  51. BOOL    intercept;                                // should we intercept msgs?
  52. BOOL    popUpMenu;                                // allow popup menu?
  53.  
  54.  
  55. //------------------------------------------------------------------------------
  56. // setFileBarScreen - sets internal position and size data our DLL needs to
  57. // correctly set the maximize screen data
  58. //------------------------------------------------------------------------------
  59. VOID EXPENTRY setFileBarScreen( BOOL position, LONG y, BOOL interceptMsgs, BOOL popUp, LONG msgID )
  60. {
  61.     messageID    = msgID;
  62.     intercept    = interceptMsgs;
  63.     popUpMenu    = popUp;
  64.     BarAtTop     = position;
  65.     ScreenY      = y;
  66.     ScreenHeight = WinQuerySysValue( HWND_DESKTOP, SV_CYSCREEN ) - y;
  67. }
  68.  
  69.  
  70. //------------------------------------------------------------------------------
  71. // Handle all input messages - search for WM_CHORD
  72. //------------------------------------------------------------------------------
  73. BOOL EXPENTRY FileBarInputHook(HAB habAnchor,PQMSG pqmMsg,ULONG ulFlags)
  74. {
  75.     //--------------------------------------------------------------------------
  76.     //
  77.     //--------------------------------------------------------------------------
  78.     if ((pqmMsg->msg == messageID) && (popUpMenu))
  79.         return WinPostMsg( hwndApp, WM_COMMAND, MPFROMLONG(POPUPMENU), MPFROMLONG(pqmMsg->hwnd) );
  80.     return FALSE;
  81. }
  82.  
  83.  
  84. //------------------------------------------------------------------------------
  85. // check to see if the window belongs to BocaSoft's WipeOut screen saver
  86. //------------------------------------------------------------------------------
  87. BOOL isScreenSaver( HWND window )
  88. {
  89.     SWCNTRL swctl;
  90.  
  91.     WinQuerySwitchEntry( WinQuerySwitchHandle( window, 0 ), &swctl );
  92.     return (!stricmp( swctl.szSwtitle, "BocaSoft WipeOut" ));
  93. }
  94.  
  95.  
  96. //------------------------------------------------------------------------------
  97. // FileBarHook - this is called whenever a message is sent in the system.  So,
  98. // we simply look at each message going by and if it's something dealing with
  99. // moving or maximizing, intercept and alter so that FileBar is always on top
  100. // and no maximizing covers it!
  101. //
  102. // Note:  The parameters sent to FileBarHook are defined in the SendMsg Hook
  103. //
  104. // Returns:  TRUE if the rest of the hook chain is not to be called, or FALSE
  105. //           if the rest of the hook chain should be called.
  106. //------------------------------------------------------------------------------
  107. BOOL EXPENTRY FileBarHook(HAB habAnchor,PSMHSTRUCT structurePtr,BOOL interTask)
  108. {
  109.   if (intercept)
  110.      switch(structurePtr->msg) {
  111.         //----------------------------------------------------------------------
  112.         // if any window is moved, make sare FileBar is placed on top of it
  113.         //----------------------------------------------------------------------
  114.         case WM_MOVE: {
  115.             if (!isScreenSaver( structurePtr->hwnd ))
  116.                 return WinSetWindowPos( hwndApp, HWND_TOP,0,0,0,0,SWP_ZORDER);
  117.             return FALSE;
  118.             }
  119.         //----------------------------------------------------------------------
  120.         // if a window is being maximized, make it fit below or on top of the
  121.         // FileBar application window
  122.         //----------------------------------------------------------------------
  123.         case WM_WINDOWPOSCHANGED: {
  124.           // the way BocaSoft's WipeOut screen saver is designed, when it is
  125.           // running, FileBar is still visible.  So, when that screen saver is
  126.           // requesting a maximized screen, give it access to the full screen
  127.  
  128.           if (isScreenSaver( structurePtr->hwnd ))
  129.               return FALSE;
  130.  
  131.           if (LONGFROMMP(structurePtr->mp2) & AWP_MAXIMIZED) {
  132.               PSWP pSwp = (PSWP)LONGFROMMP(structurePtr->mp1);
  133.  
  134.               if ((pSwp->x>60000) && (pSwp->y>60000)) {
  135.                 SHORT xBorder = WinQuerySysValue( HWND_DESKTOP, SV_CXSIZEBORDER );
  136.                 SHORT yBorder = WinQuerySysValue( HWND_DESKTOP, SV_CYSIZEBORDER );
  137.                 pSwp->x = -xBorder;
  138.                 pSwp->cx = WinQuerySysValue( HWND_DESKTOP, SV_CXSCREEN ) + 2*xBorder;
  139.                 pSwp->cy = ScreenHeight + yBorder + yBorder + 1;
  140.                 if ( BarAtTop ) {
  141.                     pSwp->y  = -yBorder;
  142.                     pSwp->cy--;
  143.                     }
  144.                 else
  145.                     pSwp->y = ScreenY - yBorder - 1;
  146.  
  147.                 return WinSetWindowPos( structurePtr->hwnd, 0, pSwp->x, pSwp->y, pSwp->cx, pSwp->cy, SWP_MOVE|SWP_SIZE);
  148.                 }
  149.  
  150.             }
  151.           }
  152.         default:
  153.             break;
  154.         }
  155.     return FALSE;
  156. }
  157.  
  158.  
  159. //------------------------------------------------------------------------------
  160. // FileBarInit - initialize FileBar DLL.  This will load in the DLL, store the
  161. // handle to the module and set the system hook so that we intercept messages
  162. //
  163. // Returns:  TRUE if successful, FALSE otherwise
  164. //------------------------------------------------------------------------------
  165. BOOL EXPENTRY FileBarInit( HWND hwnd )
  166. {
  167.    hwndApp = hwnd;
  168.  
  169.    if (DosQueryModuleHandle(DLL_NAME,&hmModule))
  170.       return FALSE;
  171.  
  172.    WinBroadcastMsg(HWND_DESKTOP,WM_NULL,0,0,BMSG_FRAMEONLY|BMSG_POST);
  173.    WinSetHook(WinQueryAnchorBlock(hwndApp),
  174.               NULLHANDLE,
  175.               HK_SENDMSG,
  176.               (PFN)FileBarHook,
  177.               hmModule);
  178.    WinBroadcastMsg(HWND_DESKTOP,WM_NULL,0,0,BMSG_FRAMEONLY|BMSG_POST);
  179.    WinSetHook(WinQueryAnchorBlock(hwndApp),
  180.               NULLHANDLE,
  181.               HK_INPUT,
  182.               (PFN)FileBarInputHook,
  183.               hmModule);
  184.    return WinBroadcastMsg(HWND_DESKTOP,WM_NULL,0,0,BMSG_FRAMEONLY|BMSG_POST);
  185. }
  186.  
  187.  
  188. //-------------------------------------------------------------------------
  189. // FileBarQuit - this releases the FileBar DLL
  190. // Returns:  TRUE always
  191. //-------------------------------------------------------------------------
  192. BOOL EXPENTRY FileBarQuit( VOID )
  193. {
  194.    WinReleaseHook(WinQueryAnchorBlock(hwndApp),
  195.                   NULLHANDLE,
  196.                   HK_SENDMSG,
  197.                   (PFN)FileBarHook,
  198.                   hmModule);
  199.    WinBroadcastMsg(HWND_DESKTOP,WM_NULL,0,0,BMSG_FRAMEONLY|BMSG_POST);
  200.    WinReleaseHook(WinQueryAnchorBlock(hwndApp),
  201.                   NULLHANDLE,
  202.                   HK_INPUT,
  203.                   (PFN)FileBarInputHook,
  204.                   hmModule);
  205.    return WinBroadcastMsg(HWND_DESKTOP,WM_NULL,0,0,BMSG_FRAMEONLY|BMSG_POST);
  206. }
  207.  
  208.